package com.xyre.client.framework.util;

import android.text.TextUtils;

import java.util.regex.Pattern;

/**
 * 判断字符串数字工具类
 * @author shenfeifei
 *
 */
public class NumberJudgmentUtil {
	
	private NumberJudgmentUtil(){}

	
	public static boolean isNumber(String num, int maxFloat, double max) {
		if (isDouble(num)) {
			String[] ls = num.split("\\.");
			boolean flag = ls[1].length() <= maxFloat ? true : false;
			if(flag){
				double y= Double.parseDouble(num);
				if(y<=max)
					return true;
			}
			

		} else if (isNumeric(num)) {
			double x= Double.parseDouble(num);
			if(x<=max){
				return true;
			}
			

		}

		return false;
	}


	public static boolean isNumeric(String str) {
		Pattern pattern = Pattern.compile("[0-9]*");
		return pattern.matcher(str).matches();
	}


	public  static boolean isDouble(String str) {
		if (str == null) {
			return false;
		}
		try {
			Double.parseDouble(str);
		} catch (NumberFormatException e) {
			return false;
		}

		if (str.contains(".")&&str.split("\\.").length==2) {
			String ls=str.split("\\.")[0];
			if(TextUtils.isEmpty(ls)){
				return false;
			}
			else if(ls.contains("-")||ls.contains("+")){
				return false;
			}
			else{
				return true;
			}
		}
		return false;
	}

}
